<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/8
 * Time: 11:48
 */

namespace App\Utils;


class LogUtils
{
    /**
     * 写日志
     * @param $msg string 日志内容
     * @param $_path string 存放路径
     * @param $log_name string 日志名称
     * @return mixed
     */
    public static function log($msg, $_path = '', $log_name = '')
    {
        $dir = substr(dirname(__FILE__), 0, -9);
        $path = $dir . env('PUBLIC_PATH').'/logs/';
        if ($_path) {
            $path .= $_path . '/';
        }
        //判断路径是否存在
        create_dir($path);
        $fp = fopen($path . $log_name . date('Ymd') . ".txt", "a");
        flock($fp, LOCK_EX);
        fwrite($fp, "执行日期：" . strftime("%Y%m%d%H%M%S", time()) . "\n" . '$path=' . $path . "\n" . $msg . "\n" . "\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }

    /**
     * excel导入 数据重复、错误储存
     * @param $_path 文件路径
     * @param $log_name 文件名称
     * @param array $data 错误数据
     * @return mixed
     */
    public static function excelLog($_path,$log_name,$data=array()){
        $dir = substr(dirname(__FILE__), 0, -9);
        $path = $dir . env('PUBLIC_PATH').'/error_logs/';
        if ($_path) {
            $path .= $_path . '/';
        }
        //判断路径是否存在
        create_dir($path);

    }
}